package com.jstyle.jclifexd.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.constraint.ConstraintLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.utils.ScreenUtils;

public class ShareBottomView extends LinearLayout {
    View constraintLayout;
    Context context;
    public ShareBottomView(Context context) {
        super(context);
        init(context);

    }

    private static final String TAG = "ShareBottomView";
    private void init(Context context){
        constraintLayout=  LayoutInflater.from(context).inflate(R.layout.layout_share_bottom, this, false);
        this.context=context;
        layoutView(constraintLayout);
    }
    private void layoutView(View v) {
        int width = ScreenUtils.getScreenWidth(context);
        int height = ScreenUtils.getScreenHeight(context);

        v.layout(0, 0, width, height);
        int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int measuredHeight = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        v.measure(measuredWidth, measuredHeight);
        v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    }

    public Bitmap getBitmap() {
        int width=constraintLayout.getWidth();
        int height=constraintLayout.getHeight();
        Bitmap originBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(originBitmap);
        constraintLayout.draw(canvas);
        return originBitmap;
    }
}
